package com.dfbz.demo01;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_递归计算求和 {
    public static void main(String[] args) {


        /*int num = 0;
        for (int i = 0; i <= 5; i++) {
            num+=i;
        }
        System.out.println(num);*/

        // 1+2+3+4+5
        int result = getSum(5);
        System.out.println(result);
    }


    public static int getSum(int num) {

        if (num == 1) {
            return 1;
        }
        return num + getSum(num - 1);
    }
}
